我在做内部系统的时候,想先显示登录界面,然后再显示系统内容,但是css跟js在登录界面不起作用。
1、下面这个是viewstart里面的
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
2、下面是layout下面的
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>信息平台</title> <link href="@Url.Content("~/Content/myFirstCss.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery-2.0.3.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/myFirstJS.js")" type="text/javascript"></script> </head> <body> <div class="top_Background"> @RenderPage("~/Views/Home/Top.cshtml") <div class="line"> </div> <table class="tb_Content"> <tr> @RenderPage("~/Views/Home/Left.cshtml") @RenderBody() </tr> </table> </div> @RenderPage("~/Views/Home/Bottom.cshtml") </body> </html>
3、下面是logon下面的
@{ Layout = null; } @model MvcApplication1.Models.LogOnModel <html> <head> <meta charset="utf-8" name="viewport" content="width=device-width" /> <title>信息平台</title> <link href="../../Content/myFirstCss.css" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/myFirstCss.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery-2.0.3.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/myFirstJS.js")" type="text/javascript"></script> </head> <body class="login_Background" > @using (Html.BeginForm()) { <div class="login_top_bg"> <div style=" height :20%;"></div> <div class="login_body"> <div class="login_top"> <div class="login_top_logo"> </div> <span id="Version" class="login_top_title">信息平台</span> </div> <div class="login_ct"> <span class="text">@Html.TextBoxFor(m => m.UserName, new { @class = "input" })<br />用户名: </span> <span class="text">@Html.PasswordFor(m => m.Password, new { @class = "input" })<br />密码:</span> <div class="login_ct_an"> <span class="line UI"> </span> <span class="an"><input type="submit" id="btnLogin" class="unSubmit" value="" style="cursor: hand" /></span> </div> </div> </div> <div class="login_copy"> Copyright © <a href="/" target="_blank"><b></b></a> All rights are reserved.<br> <a href="LogOn.cshtml">电脑版</a> | <a href="LogOn.cshtml" >手机版</a> </div> </div> } </body> </html>
显示的总是下面这个图,而且通过chrom里面审查元素可以看出css跟js都是无效,但是index上面的css等是有效的。
请高手指点,完全不会啊。或者一般做系统开发,登录与平台是怎么处理的?
由于未授权,导致css/js被跳转了。你应该用的是Form认证吧,检查一下对css/js的访问限制。
<link href="@Url.Content("~/Content/myFirstCss.css")" rel="stylesheet" type="text/css" />
把href="@Url.Content("~/Content/myFirstCss.css")"外面加上<%%>变成:
<link href="<%=Url.Content("~/Content/myFirstCss.css")%>" rel="stylesheet" type="text/css" />
你这个@作用不一样么?测试过没效果。
@Jay_Ai: 对MVC不是很熟,像<link href="@Url.Content("~/Content/myFirstCss.css")" rel="stylesheet" type="text/css" />这样以@开头的地址浏览器可以解析吗?
@沧海一杰: 可以的
webconfig中,为每个目录指定了权限。
将你的登录页面的css、js单独弄到一个目录中,在这个目录里面添加一个webconfig文件,并填写<authorization>
<allow users="*"/>
</authorization> 这个就行了。
这句话的意思是,这个目录中的所有文件,都允许所有用户访问。
@model InfoApp.Models.LogOnModel @{Layout=null;} @{ ViewBag.Title = "登录"; } <link href="@Url.Content("~/Content/myFirstCss.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @Html.ValidationSummary(true, "登录不成功。请更正错误并重试。") @using (Html.BeginForm()) { <div class="login_Background"> <div style="height: 20%;"> </div> <div class="login_body"> <div class="login_top"> <div class="login_top_logo"> </div> <span id="Version" class="login_top_title">信息平台V1.0</span> </div> <div class="login_ct"> <span class="text">@Html.TextBoxFor(m => m.UserName, new { @class = "input" })<br /> 用户名: </span><span class="text">@Html.PasswordFor(m => m.Password, new { @class = "input" })<br /> 密码:</span> <div class="login_ct_an"> <span class="line UI"> </span> <span class="an"> <input type="submit" id="btnLogin" class="unSubmit" value="" style="cursor: hand" /></span> </div> </div> </div> </div> @RenderPage("~/Views/Home/Bottom.cshtml") @* <div class="copy" style="height:20%; bottom: 0px;"> Copyright © <a href="" target="_blank"><b>www.ketengchina.com</b></a> All rights are reserved.<br> <a href="LogOn.cshtml">电脑版</a> | <a href="LogOn.cshtml">手机版</a> </div> *@ }