MVC QueryString with Guid returns 404

烂漫一生 提交于 2019-12-04 02:50:33

问题


I have a problem on my Development server.... On my local machine everything works....

This is the issue:

I have a Page that looks like this:

@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.");
}

Now, I am getting an issue....

/Profile (Show the fields for the current user and works fine)

/Profile?id=4 (states Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx))

/Profile?id=E23CB58D-BDBC-4BE5-A27C-7E6518ED72B0 (Displays 404 error...)

I have no idea why the Guid one will not work. Like I have said, this works on my local machine, but doesn't work on the Development server. I should point out that no page that accepts a guid string works, they all do the same as the Profile page....

Does anyone know why this might be happening?

Update

I have changed the code to

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

@id

and I am still getting the issue

Update 2

I changed the code to this:

@{
    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";  
}

because I figured it might be an issue with trying to use Id/id as the parameter. Anyway, I still get the same problem....


回答1:


I figured it out. It was because of this in the Web.config

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

It was the maxQueryString.

I have since removed both maxUrl and maxQueryString and it is all working now :)




回答2:


just off the cuff, are you supposed to have two ? in the url ?

Im pretty sure you can only have one ? and separate the querystring parameters with &

so you should be using this shape

/Profile?id=Profile&id=E23CB58D-BDBC-4BE5-A27C-7E6518ED72B0



来源:https://stackoverflow.com/questions/16605632/mvc-querystring-with-guid-returns-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!