英文:
TempData[] does not work on the IIS server, but works on the local computer
问题
我有一个控制器,输出一条消息,然后重定向到Index()。问题是,这段代码在本地机器上能正常运行,但在IIS上发布时,无法输出消息,而其他代码则正常工作。控制器代码:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult LoadFile(HttpPostedFileBase fileExcel)
{
if (ModelState.IsValid)
{
try
{
#region check
if (fileExcel == null)
{
TempData["AlertMessage"] = "aboba";
return RedirectToAction("Index");
}
#endregion
...
}
...
}
}
IIS版本为10.0
我尝试用Session替换TempData,但没有帮助。
英文:
I have a controller that outputs a message and then redirects to Index(). The problem is that the code works properly on the local machine, and when publishing on IIS does not want to output a message, and the rest of the code works correctly. Controller Code:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult LoadFile(HttpPostedFileBase fileExcel)
{
if (ModelState.IsValid)
{
try
{
#region check
if (fileExcel == null)
{
TempData["AlertMessage"] = "aboba";
return RedirectToAction("Index");
}
#endregion
...
}
}
}
IIS version 10.0
I tried to replace TempData with Session, but it didn't help.
答案1
得分: 0
默认情况下,TempData 存储在会话状态中,这意味着 Web 应用程序必须启用会话。如果禁用了 TempData,它将无法正常工作。
您可以通过查找以下行来检查应用程序的 Web.config 文件中是否启用了会话状态:
<sessionState mode="InProc" />
英文:
By default, TempData is stored in session state, which means that the web application must have sessions enabled. If TempData is disabled, it will not work as expected.
You can check if session state is enabled in your application Web.config file by looking for the following line:
<sessionState mode="InProc" />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论