带Guid的MVC QueryString返回404

时间:2013-05-17 09:24:04

标签: asp.net-mvc-routing

我的开发服务器上有问题.... 在我的本地机器上一切正常......

这就是问题所在:

我有一个看起来像这样的页面:

@using Skipstone.Web;
@using Skipstone.Web.Providers;
@using Skipstone.Web.Extensions

@{
    string id = (Request.QueryString["id"] == null) ? ProfileProvider.CurrentUser().UserId : Request.QueryString["id"];
    Profile user = new Profile(id);
    ViewBag.Title = "Profile - " + user.Surname + ", " + user.Forename;
    string credentialId = (user.CredentialId != null && user.CredentialId != "") ? user.CredentialId : "Credential Id";  
}


@if (id != null) {
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>

    <div class="container">
        <div class="row">
            <div class="sixcol">
                <div class="profile">
                    @if (!string.IsNullOrEmpty(user.Photo))
                    {
                        <img src="@user.Photo" />
                    }
                    else
                    {
                        <img src="/Content/media/user.png" />
                    }
                    <h2>@user.Forename @user.Surname</h2>
                    <h3>@user.JobTitle</h3>
                    <p>@HtmlExtensions.decodeEscapedText(user.Bio)</p>
                </div>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <div class="sixcol">
                <div class="message"></div>
            </div>
            <div class="sixcol">
            </div>
        </div>
    </div> 

    <div class="container" id="profile-view">
        <div class="row">
            <div class="sixcol">
                <div class="profile form">
                    @if (id == ProfileProvider.CurrentUser().UserId)
                    {
                        <a href="#" class="button edit small" style="float: right;">Edit</a>
                    }
                    <ul>
                        @if (user.Telephone != null && user.Telephone != "")
                        { <li class="profile-tel"><span class="icon"></span><span>@user.Telephone</span></li> }
                        @if (user.Mobile != null && user.Mobile != "")
                        { <li class="profile-mob"><span class="icon"></span><span>@user.Mobile</span></li> }
                        @if (user.Email != null && user.Email != "")
                        { <li class="profile-email"><span class="icon"></span><span><a href="mailto:@user.Email">@user.Email</a></span></li> }
                    </ul>
                    <ul>
                        @if (user.Twitter != null && user.Twitter != "")
                        { <li class="profile-twitter"><span class="icon"></span><span><a href="mailto:@user.Twitter">@user.Twitter</a></span></li> }
                        @if (user.Facebook != null && user.Facebook != "")
                        { <li class="profile-facebook"><span class="icon"></span><span><a href="mailto:@user.Facebook">@user.Facebook</a></span></li> }
                        @if (user.LinkedIn != null && user.LinkedIn != "")
                        { <li class="profile-linked"><span class="icon"></span><span><a href="mailto:@user.LinkedIn">@user.LinkedIn</a></span></li> }
                    </ul>
                </div>
            </div>
            <div class="sixcol"></div>
        </div>
    </div> 

    <form id="profile-edit" style="display: none;">
        <div class="container">
            <div class="row">
                <div class="sixcol">
                    <div class="form form-top form-bottom">                    
                        <input type="hidden" id="UserId" name="UserId" value="@user.UserId" />
                        <input type="hidden" id="CompanyName" name="CompanyName" value="@user.CompanyName" />
                        <input type="hidden" id="Photo" name="Photo" value="@user.Photo" />
                        <input type="hidden" id="UserCanEdit" name="UserCanEdit" value="@user.UserCanEdit" />
                        <input type="hidden" id="UserCanEditOwn" name="UserCanEditOwn" value="@user.UserCanEditOwn" />
                        <input type="hidden" id="UserCanApprove" name="UserCanApprove" value="@user.UserCanApprove" />
                        <input type="hidden" id="UserRequiresApproval" name="UserRequiresApproval" value="@user.UserRequiresApproval" />

                        <label class="block-label" for="Title">Title</label>
                        <div class="textbox"><input type="text" class="required" name="Title" id="Title" value="@user.Title" /></div>

                        <label class="block-label" for="Forname">Forname(s)</label>
                        <div class="textbox"><input type="text" class="required" name="Forename" id="Forename" value="@user.Forename" /></div>

                        <label class="block-label" for="Surname">Surname</label>
                        <div class="textbox"><input type="text" class="required" name="Surname" id="Surname" value="@user.Surname" /></div>

                        <label class="block-label" for="UserName">Username</label>
                        <div class="textbox"><input type="text" class="required" id="UserName" name="UserName" value="@user.UserName" /></div>

                        <label class="block-label" for="file">Upload profile image</label>
                        <div class="textbox file"><input type="file" id="file" name="file" /></div>

                        <label class="block-label" for="JobTitle">Job title</label>
                        <div class="textbox"><input type="text" name="JobTitle" id="JobTitle" value="@user.JobTitle" /></div>

                        <label class="block-label" for="Telephone">Telephone</label>
                        <div class="textbox"><input type="text" name="Telephone" id="Telephone" value="@user.Telephone" /></div>

                        <label class="block-label" for="Mobile">Mobile</label>
                        <div class="textbox"><input type="text" name="Mobile" id="Mobile" value="@user.Mobile" /></div>

                        <label class="block-label" for="Email">Email address</label>
                        <div class="textbox"><input type="text" class="required" name="Email" id="Email" value="@user.Email" /></div>

                        @if (SettingsProvider.CurrentSiteSettings().TwoFactorAuthentication)
                        { 
                            <label class="block-label" for="CredentialId">Credential Id</label>  
                            <div class="textbox"><input type="text" class="required" id="CredentialId" name="CredentialId" value="@user.CredentialId" /></div>
                            <input type="hidden" class="required" name="Code" value="Security Code" />
                        }
                        else
                        {
                            <input type="hidden" class="required" name="CredentialId" value="@credentialId" />
                            <input type="hidden" class="required" name="Code" value="Security Code" />
                        }   

                        <label class="block-label" for="LinkedIn">LinkedIn</label>
                        <div class="textbox"><input type="text" name="LinkedIn" id="LinkedIn" value="@user.LinkedIn" /></div>

                        <label class="block-label" for="Twitter">Twitter</label>
                        <div class="textbox"><input type="text" name="Twitter" id="Twitter" value="@user.Twitter" /></div>

                        <label class="block-label" for="Facebook">Facebook</label>
                        <div class="textbox"><input type="text" name="Facebook" id="Facebook" value="@user.Facebook" /></div>

                        <label class="block-label" for="Bio">Bio</label>
                        <div class="textbox"><textarea id="Bio" name="Bio" rows="9">@user.Bio</textarea></div>

                        <div class="action">
                            <button>Save</button>
                        </div>
                        <button id="cancel">Cancel</button>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <script src="@Url.Content("~/Scripts/jquery.skipstone-profile-save.js")" type="text/javascript"></script>
}
else
{
    throw new Exception("Invalid id specified.");
}

现在,我遇到了一个问题......

/个人资料(显示当前用户的字段并且工作正常)

/个人资料?id = 4(状态Guid应包含32个数字,包含4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx))

/个人资料?id = E23CB58D-BDBC-4BE5-A27C-7E6518ED72B0(显示404错误......)

我不知道为什么Guid会不起作用。 就像我说的,这适用于我的本地机器,但不适用于开发服务器。 我应该指出,没有接受guid字符串的页面可以工作,它们都与Profile页面相同....

有谁知道为什么会这样?

更新

我已将代码更改为

@{
    string id = Request.QueryString["id"];  
}

@id

我仍然遇到问题

更新2

我将代码更改为:

@{
    string id = (Request.QueryString["UserId"] == null) ? ProfileProvider.CurrentUser().UserId : Convert.ToString(Request.QueryString["UserId"]);
    Profile user = new Profile(id);
    ViewBag.Title = "Profile - " + user.Surname + ", " + user.Forename;
    string credentialId = (user.CredentialId != null && user.CredentialId != "") ? user.CredentialId : "Credential Id";  
}

因为我认为尝试使用Id / id作为参数可能是一个问题。无论如何,我仍然遇到同样的问题......

2 个答案:

答案 0 :(得分:1)

我明白了。 这是因为在Web.config

<requestLimits maxAllowedContentLength="1048576000" maxUrl="260" maxQueryString="25" />

这是maxQueryString。

我已经删除了maxUrl和maxQueryString,现在一切正常:)

答案 1 :(得分:0)

只是脱下袖口,你应该有两个吗?在网址?

我很确定你只能有一个吗?并使用&amp;

分隔查询字符串参数

所以你应该使用这个形状

/配置文件ID =简介&安培;?ID = E23CB58D-BDBC-4BE5-A27C-7E6518ED72B0