简体   繁体   English

HTML链接onclick,jquery函数,redirectToAction IIS服务器不起作用?

[英]Html link onclick, jquery function, redirectToAction IIS server doesnt work?

I am struggling to use my submenus after publishing to IIS server. 发布到IIS服务器后,我很难使用子菜单。 For some reason the first redirect works properly, it gives me a 302 found. 由于某种原因,第一个重定向工作正常,结果为302。 Then when it attempts to redirect to action and return a partialview it gives me a 500 internal server error code. 然后,当它尝试重定向到操作并返回partialview时,给了我500内部服务器错误代码。

I am trying to update a partialview inside another partial view. 我正在尝试在另一个局部视图中更新局部视图。 This code works locally in a VS environment, but when I push it to a IIS Server it doesnt work. 该代码在VS环境中本地工作,但是当我将其推送到IIS服务器时,它不起作用。

I have tried searching for quite some time but cannot find anything that works. 我尝试搜索了一段时间,但找不到任何有效的方法。 I am fairly new to MVC and IIS. 我是MVC和IIS的新手。

My html looks like this: 我的html看起来像这样:

<div class="wrapper">
    <ul id="submenu">
        <li><a class="LinkPart" href="#" onclick="getPartial(1);">Some subpage</a></li>
        <li><a class="LinkPart" href="#" onclick="getPartial(2);">Some subpage</a></li>
        <li><a class="LinkPart" href="#" onclick="getPartial(3);">Some subpage</a></li>
        <li><a class="LinkPart" href="#" onclick="getPartial(4);">Some subpage</a></li>
        <li><a class="LinkPart" href="#" onclick="getPartial(5);">Some subpage</a></li>
        <li><a class="LinkPart" href="#" onclick="getPartial(6);">Some subpage</a></li>
    </ul>
</div>

<div class="right-box">
    <div id="right-box" class="data" style="visibility:visible;">
        @Html.Partial("~/Views/Admin/_AdminPartial.cshtml")
    </div>

</div>

Javascript at the bottom of the cshtml cshtml底部的Javascript

function getPartial(y) {
    $.get(location.href = '@Url.Action("_PartialPickAdminpage", "Admin")/' + y, function (data) {
        $('div#right-box.data').html(data);
    })
}

and my Controller looks like this, with an example of one of the actions: 我的控制器看起来像这样,并举例说明了其中一项操作:

[Authorize(Roles = "Administrator")]
    [HttpGet]
    public ActionResult _PartialPickAdminpage ( string id )
    {
        int newid = Convert.ToInt32(id);
        Debug.WriteLine("id partialpickAdminpage: " + id);
        if (newid.Equals(1))
        {
            return RedirectToAction("Register", "Account");
        }
        else if (newid.Equals(2))
        {
            return RedirectToAction("_SomePagePartial");
        }
        else if (newid.Equals(3))
        {
            return RedirectToAction("_SomePagePartial");
        }
        else if (newid.Equals(4))
        {
            return RedirectToAction("_SomePagePartial");
        }
        else if (newid.Equals(5))
        {
            return RedirectToAction("_SomePagePartial");
        }
        else if (newid.Equals(6))
        {
            return RedirectToAction("_SomepagePartial");
        }
        else
        {
            return PartialView("~/Views/Account/_ChangePasswordPartial.cshtml");
        }
    }

[Authorize(Roles = "Administrator")]
public PartialViewResult _SomePagePartial()
{
    TempData["ErrorMessage"] = "";
    return PartialView("~/Views/Admin/_SomePagePartial.cshtml");
}

One of the things I have noticed is that whenever I click one of the links it runs the _PartialPickAdminpage call twice locally, but only once and times out on IIS. 我注意到的一件事是,每当我单击其中一个链接时,它都会在本地运行_PartialPickAdminpage调用两次,但在IIS上仅运行一次且超时。

Found this in the logfile on the server. 在服务器的日志文件中找到了它。

    2016-12-19 10:46:53 192.168.0.145 GET /playlist - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 - 200 0 0 62
    2016-12-19 10:46:53 192.168.0.145 GET /Playlist/Views/StyleSheet.css - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 http://to-be-more/playlist 404 0 0 0
    2016-12-19 10:46:53 192.168.0.145 GET /Playlist/Views/StyleSheet.css - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 http://to-be-more/playlist 404 0 0 15
    2016-12-19 10:47:00 192.168.0.145 GET /Playlist/Admin/AdminSection - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 http://to-be-more/playlist 200 0 0 46
    2016-12-19 10:47:10 192.168.0.145 GET /Playlist/Admin/_PartialPickAdminpage/1 - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 http://to-be-more/Playlist/Admin/AdminSection 302 0 0 0
    2016-12-19 10:47:10 192.168.0.145 GET /Playlist/Admin/_PartialPickAdminpage/1 - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 http://to-be-more/Playlist/Admin/AdminSection 302 0 0 203
2016-12-19 10:47:40 192.168.0.145 GET /Playlist/Account/Register - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 http://to-be-more/Playlist/Admin/AdminSection 500 0 0 30150
2016-12-19 10:48:10 192.168.0.145 GET /Playlist/Account/Register - 80 nasoon 192.168.0.137 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36 http://to-be-more/Playlist/Admin/AdminSection 500 0 0 40306

The Account controller with the Register action: 具有“注册”操作的帐户控制器:

        [Authorize(Roles = "Administrator")]
    [HttpGet]
    public ActionResult Register()
    {
        UserRepository ur = new UserRepository();
        var list = ur.MyListTable();
        var model = new RegisterModel();
        model.DropDownList = new SelectList(list, "RoleID", "RoleName");
        return PartialView(model);
    }

Connection string to database, starred out user and password: 与数据库的连接字符串,标出了用户名和密码:

Data Source=TO-BE-MORE\SQL2016;Initial Catalog=tbmplaylist;Persist Security Info=True;User ID=****;Password=****

1) The database connectivity was not happening initially so 500 internal error.[timeout execption] Some functions used local connectionstrings (ADO.net). 1)最初没有发生数据库连接,因此出现500内部错误。[超时执行]某些函数使用本地连接字符串(ADO.net)。 Use two connection strings in web.config, one for EF and one for ADO.net. 在web.config中使用两个连接字符串,一个用于EF,一个用于ADO.net。

<add name="Database1Entities" connectionString="metadata=res://*/Models.Database1Entities1.csdl|res://*/Models.Database1Entities1.ssdl|res://*/Models.Database1Entities1.msl;provider=System.Data.SqlClient;provider connection string='Data Source=TO-BE-MORE\SQL2016;initial catalog=tbmplaylist;MultipleActiveResultSets=True;User ID=****;Password=****;Connection Timeout=120;App=EntityFramework'" providerName="System.Data.EntityClient"/>
<add name="Database1EntitiesADO" connectionString="Data Source=TO-BE-MORE\SQL2016;initial catalog=tbmplaylist;MultipleActiveResultSets=True;User ID=***;Password=****;Connection Timeout=120;App=EntityFramework"/>

Then in methods call like this: 然后在这样的方法中调用:

System.Configuration.ConfigurationManager.ConnectionStrings["Database1EntitiesADO"].ConnectionString

2) The action which is called will return an actionresult . 2)被调用的动作将返回一个动作结果。 So wont be getting partial result. 所以不会得到部分结果。

3) Redirecttoaction creates a new request so the initial query will first get executed and then end_request will be called then new_request is created that is the reason for twice execution. 3)Redirecttoaction创建一个新请求,因此将首先执行初始查询,然后将调用end_request,然后创建new_request,这是执行两次的原因。

Changing the jquery scripts to look like this fixed issues 2 and 3: 更改jQuery脚本使其看起来像已解决的问题2和3:

        function getPartial(y) {
        $.get('_PartialPickAdminpage/' + y, function (data) {
            $('div#right-box.data').html(data);
        })
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM