Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Check if HttpResponseMessage = HttpStatusCode.NotFound

Posted on 2013-05-31
1
Medium Priority
?
737 Views
Last Modified: 2013-06-03
Hi!

In my ASP.NET Web API (MVC4) I need to check what a method called UserExists() returns. If it is "HttpStatusCode.NotFound" I need to do something, if not I will do something else. Please see code below. How can this be easily done?

protected HttpResponseMessage UserExists(string userName)
{
    var mp = Membership.Providers[API.CurrentSite.ApplicationName];
    var user = mp.GetUser(userName.Trim(), false);

    if (user != null)
    {
	return Request.CreateResponse(HttpStatusCode.Found);
    }
    return Request.CreateResponse(HttpStatusCode.NotFound);
}

public HttpResponseMessage PostUser(API.Models.UserData user)
{
    if (UserExists(user.UserName) == HttpStatusCode.NotFound) //THIS CHECK DON'T WORK 
    {
        // Do something
    }
    else
    {
        // Do something else
    }
{

Open in new window

0
Comment
Question by:webressurs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39210538
Check the StatusCode property:

if (UserExists(user.UserName).StatusCode == HttpStatusCode.NotFound)

Open in new window

0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question