如何解决ASP.NET MVC 应用程序在生产中发布后不起作用
我一直在开发一个 asp.net mvc 应用程序,它在我的开发电脑中功能齐全,但在生产环境中部署后(iis 7.5,WS 2008 R2)它不起作用。当我提供登录凭据并使用相同的登录页面提交 ajax post 请求返回 200 ok 时,它没有命中控制器 post 方法。
-
Web.config:-
<system.web> <httpRuntime targetFramework="4.5" /> <compilation debug="true" targetFramework="4.5" /> <authentication mode="Forms"> <forms name="IMTCMS" loginUrl="~/Account/RedirectToLogin" protection="All" timeout="30" /> </authentication> <pages> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptprocessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,OPTIONS" modules="IsapiModule" scriptprocessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer>
-
登录.cshtml:-
<!DOCTYPE html>
<html lang="en">
<head>
<Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<Meta charset="utf-8" />
<title>Login Page - Ace Admin</title>
<Meta name="description" content="User login page" />
<Meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="~/Content/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/Content/font-awesome/4.2.0/css/font-awesome.min.css" />
<!-- text fonts -->
<link rel="stylesheet" href="~/Content/fonts/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="~/Content/css/ace.min.css" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="~/Content/css/ace-part2.min.css" />
<![endif]-->
<link rel="stylesheet" href="~/Content/css/ace-rtl.min.css" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="~/Content/css/ace-ie.min.css" />
<![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="~/Content/js/html5shiv.min.js"></script>
<script src="~/Content/js/respond.min.js"></script>
<![endif]-->
</head>
<body class="login-layout light-login" style="background: url(../Content/img/Globalfootprint.jpg) no-repeat center center fixed;background-size:cover;">
<div class="main-container">
<div class="main-content">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="login-container ">
<div class="center">
</div>
<div class="space-6"></div>
<div class="position-relative">
<div id="login-Box" class="login-Box visible widget-Box no-border">
<div class="widget-body">
<div class="widget-main">
<h1 class="center">
<i class="ace-icon fa fa-leaf green"></i>
<span class="red">IMT</span>
<span class="grey" id="id-text2">SMS</span>
</h1>
<h4 class="blue" id="id-company-text">© Beximco Pharmaceuticals Ltd.</h4>
<h4 class="header blue lighter bigger">
<i class="ace-icon fa fa-coffee green"></i>
Please Enter Your information
</h4>
<div class="space-6"></div>
<form>
<fieldset>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<input type="text" class="form-control" id="username" placeholder="Username" />
<i class="ace-icon fa fa-user"></i>
</span>
</label>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<input type="password" id="password" class="form-control" placeholder="Password" />
<i class="ace-icon fa fa-lock"></i>
</span>
</label>
<div class="space"></div>
<div class="clearfix">
<label class="inline">
<input type="checkBox" class="ace" />
<span class="lbl"> Remember Me</span>
</label>
<a type="button" class="width-35 pull-right btn btn-sm btn-primary" onclick="UserLogin();">
<i class="ace-icon fa fa-key"></i>
<span class="bigger-110">Login</span>
@*<a class="btn btn-default submit" href="@Url.Action("ModeList","Home")">Log in</a>*@
</a>
</div>
<div class="space-4"></div>
</fieldset>
</form>
</div><!-- /.widget-main -->
<div class="toolbar clearfix">
<div>
<a href="#" data-target="#forgot-Box" class="forgot-password-link">
<i class="ace-icon fa fa-arrow-left"></i>
I forgot my password
</a>
</div>
<div>
<a href="#" data-target="#signup-Box" class="user-signup-link">
I want to register
<i class="ace-icon fa fa-arrow-right"></i>
</a>
</div>
</div>
</div><!-- /.widget-body -->
</div><!-- /.login-Box -->
<div id="forgot-Box" class="forgot-Box widget-Box no-border">
<div class="widget-body">
<div class="widget-main">
<h4 class="header red lighter bigger">
<i class="ace-icon fa fa-key"></i>
Retrieve Password
</h4>
<div class="space-6"></div>
<p>
Enter your email and to receive instructions
</p>
<form>
<fieldset>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<input type="email" class="form-control" placeholder="Email" />
<i class="ace-icon fa fa-envelope"></i>
</span>
</label>
<div class="clearfix">
<button type="button" class="width-35 pull-right btn btn-sm btn-danger">
<i class="ace-icon fa fa-lightbulb-o"></i>
<span class="bigger-110">Send Me!</span>
</button>
</div>
</fieldset>
</form>
</div><!-- /.widget-main -->
<div class="toolbar center">
<a href="#" data-target="#login-Box" class="back-to-login-link">
Back to login
<i class="ace-icon fa fa-arrow-right"></i>
</a>
</div>
</div><!-- /.widget-body -->
</div><!-- /.forgot-Box -->
<div id="signup-Box" class="signup-Box widget-Box no-border">
<div class="widget-body">
<div class="widget-main">
<h4 class="header green lighter bigger">
<i class="ace-icon fa fa-users blue"></i>
New User Registration
</h4>
<div class="space-6"></div>
<p> Enter your details to begin: </p>
<form>
<fieldset>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<input type="email" class="form-control" placeholder="Email" />
<i class="ace-icon fa fa-envelope"></i>
</span>
</label>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<input type="text" class="form-control" placeholder="Username" />
<i class="ace-icon fa fa-user"></i>
</span>
</label>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<input type="password" class="form-control" placeholder="Password" />
<i class="ace-icon fa fa-lock"></i>
</span>
</label>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<input type="password" class="form-control" placeholder="Repeat password" />
<i class="ace-icon fa fa-retweet"></i>
</span>
</label>
<label class="block">
<input type="checkBox" class="ace" />
<span class="lbl">
I accept the
<a href="#">User Agreement</a>
</span>
</label>
<div class="space-24"></div>
<div class="clearfix">
<button type="reset" class="width-30 pull-left btn btn-sm">
<i class="ace-icon fa fa-refresh"></i>
<span class="bigger-110">Reset</span>
</button>
<button type="button" class="width-65 pull-right btn btn-sm btn-success">
<span class="bigger-110">Register</span>
<i class="ace-icon fa fa-arrow-right icon-on-right"></i>
</button>
</div>
</fieldset>
</form>
</div>
<div class="toolbar center">
<a href="#" data-target="#login-Box" class="back-to-login-link">
<i class="ace-icon fa fa-arrow-left"></i>
Back to login
</a>
</div>
</div><!-- /.widget-body -->
</div><!-- /.signup-Box -->
</div><!-- /.position-relative -->
</div>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.main-content -->
</div><!-- /.main-container -->
<!-- basic scripts -->
<!--[if !IE]> -->
<script src="~/Content/js/jquery.2.1.1.min.js"></script>
<!-- <![endif]-->
<!--[if IE]>
<script src="~/Content/js/jquery.1.11.1.min.js"></script>
<![endif]-->
<!--[if !IE]> -->
<script type="text/javascript">
window.jQuery || document.write("<script src='~/Content/js/jquery.min.js'>" + "<" + "/script>");
</script>
<!-- <![endif]-->
<!--[if IE]>
<script type="text/javascript">
window.jQuery || document.write("<script src='~/Content/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
<script type="text/javascript">
if ('ontouchstart' in document.documentElement) document.write("<script src='~/Content/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
jQuery(function ($) {
$(document).on('click','.toolbar a[data-target]',function (e) {
e.preventDefault();
var target = $(this).data('target');
$('.widget-Box.visible').removeClass('visible');//hide others
$(target).addClass('visible');//show target
});
});
</script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
//fill the vehicale type
//getVehicleType();
});
function UserLogin() {
// Step 1: Read View Data and Create JSON Object
// Creating info Json Object
var info = { "EmpID": "","Password": "" };
// Set info Json Object Value
info.EmpID = $("#username").val();
info.Password = $("#password").val();
//info.Condition = "1";
// Step 1: Ends Here
// Set 2: Ajax Post
// Here i have used ajax post for saving/updating information
$.ajax({
url: '/Account/Login',data: JSON.stringify(info),type: 'POST',contentType: 'application/json; charset=utf-8',dataType: 'json',success: function (result) {
if (result.Success == "1") {
window.location.href = result.url;
alert("User saved successfully,please check mail to confirm registration and then login");
return;
}
else if (result.Success == "2") {
alert(result.ex);
return;
}
else {
alert(result.ex);
}
},error: function (result) {
alert(result);
}
});
}
//*********Start : informationSave() Function
//This function is used for sending data(JSON Data) to Account Controller
function NewRegistration() {
// Step 1: Read View Data and Create JSON Object
// Creating info Json Object
var info = { "Email": "","EmpID": "","Password": "","PhoneNo": "","DeptUID": "","Condition": "" };
// Set info Json Object Value
info.Email = $("#email-address").val();
info.EmpID = $("#emp-code").val();
info.Password = $("#password").val();
info.PhoneNo = $("#phone-no").val();
info.DeptUID = $("#department").val();
info.Condition = "1";
//info.UID = "1";
//info.InfoID = "1";
// Step 1: Ends Here
// Set 2: Ajax Post
// Here i have used ajax post for saving/updating information
$.ajax({
url: '/Account/ProfileEntry',success: function (result) {
if (result.Success == "1") {
alert("User saved successfully,please check mail to confirm registration and then login");
//window.location.href = "#";
return;
}
else if (result.Success == "2") {
var error = '';
//if Problem happend during the validation,display
// the messages. The following script will display the last
// message related to the field.
//$.each(result.ex,function (key,value) {
// if (value != null) {
// error += value[value.length - 1].ErrorMessage + '\n';
// }
//});
//alert(error);
alert(result.ex);
return;
}
else {
alert(result.ex);
}
}
});
}
//*********End : informationSave() Function
//*********Start : PasswordSave() Function
//This function is used for sending data(JSON Data) to Account Controller
function ForgotPassword() {
// Step 1: Read View Data and Create JSON Object
// Creating info Json data
var email = $("#email-add").val();
//alert(email);
// Step 1: Ends Here
// Set 2: Ajax Post
// Here i have used ajax post for saving/updating information
$.ajax({
url: '/Account/ForgotPassword',data: { "email": email },//contentType: 'application/json;',//dataType: 'json',success: function (result) {
if (result.Success == "1") {
alert(result.ex);
return;
}
else if (result.Success == "2") {
alert(result.ex);
return;
}
else {
alert(result.ex);
}
}
});
}
//*********End : PasswordSave() Function
</script>
</body>
</html>
-
帐户控制器:-
public class AccountController : Controller { private LoginManager loginManager = null; LoginUser loginUser = null; [HttpGet] [AllowAnonymous] public ActionResult Login() { return View(); } [HttpGet] [Authorize] public ActionResult logoff() { try { loginUser = HttpContext.Session["UserProfile"] as LoginUser; new LoginManager().LoginManagement(new User { UID = loginUser.SlNo,Condition = "2" }); FormsAuthentication.SignOut(); } catch { FormsAuthentication.SignOut(); } return RedirectToAction("Login","Account"); } // URL to redirect user to login page when session timeout // GET: /Account/RedirectToLogin [HttpGet] public ActionResult RedirectToLogin() { return PartialView("_RedirectToLogin"); } [HttpPost] [AllowAnonymous] public ActionResult Login(User info) { try { if (ModelState.IsValid) { //get user browser information info.browserInfo = "( browser : " + HttpContext.Request.browser.browser + " ) (Version : " + HttpContext.Request.browser.Version + " ) ( Type : " + HttpContext.Request.browser.Type + " ) ( Platform : " + HttpContext.Request.browser.Platform + " ) ( UserAgent : " + HttpContext.Request.UserAgent + " ) ( UserLang : " + HttpContext.Request.UserLanguages[0].ToString() + " ) " ; loginManager = new LoginManager(); LoginUser loginuser = loginManager.GetUserInfo(info); if (loginuser != null) { FormsAuthentication.SetAuthCookie(info.EmpID,false); HttpContext.Session["UserProfile"] = loginuser; //start : new change 31/05/2017 var authTicket = new FormsAuthenticationTicket(1,info.EmpID,DateTime.Now,DateTime.Now.AddMinutes(20),false,"Admin"); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName,encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); //end : new change 31/05/2017 return Json(new { Success = 1,url = Url.Action("Index","Dashboard") }); } } else { return Json(new { Success = 2,ex = "Please fill all (*) required fields" }); } } catch (Exception ex) { // If Sucess== 0 then Unable to perform Save/Update Operation and send Exception to View as JSON return Json(new { Success = 0,ex = ex.Message.ToString() }); } finally { //accountManager = null; info = null; } return View(); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。