TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
niketa yadav
NA
96
904
Accessing Web API after hosting asp.net website
Aug 6 2020 6:28 AM
I have written a simple web API in the existing asp.net webforms project and published it on HostGator shared hosting.
API was working fine locally but not accessible after hosting.
Process how I created this API in My web forms project.
Step 1. I added a new Web API controller class to my Webform project by
right-click on webform project ->Add->Web API Controller class.
Step 2 .Added some routing information to Application_Start () methof of global.asax file .
GlobalConfiguration.Configure(WebApiConfig.Register);
public
static
class
WebApiConfig
{
public
static
void
Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name:
"DefaultApi"
,
routeTemplate:
"api/{controller}/{id}"
,
defaults:
new
{ action =
"GetRadarData"
, id = System.Web.Http.RouteParameter.Optional }
);
}
}
Step 3: Adding code to the controller class for Get method.
public
IEnumerable<clsRadarInfoEnt> GetRadarData(
string
userId,
string
password)
{
string
Response =
""
;
clsLibrary.mGetRadarList(userId, password,
out
RadarList,
out
Response);
if
(RadarList ==
null
&& Response ==
"Invalid login"
)
{
var response =
new
HttpResponseMessage(HttpStatusCode.NotFound)
{
Content =
new
StringContent(
"User doesn't exist"
, System.Text.Encoding.UTF8,
"text/plain"
),
StatusCode = HttpStatusCode.NotFound
};
throw
new
HttpResponseException(response);
}
else
if
(RadarList ==
null
&& Response ==
"Incorrect password"
)
{
var response =
new
HttpResponseMessage(HttpStatusCode.Unauthorized)
{
Content =
new
StringContent(
"Incorrect Password"
, System.Text.Encoding.UTF8,
"text/plain"
),
StatusCode = HttpStatusCode.NotFound
};
throw
new
HttpResponseException(response);
}
else
{
return
RadarList;
}
}
It was working fine locally and giving the result as aspected but after hosting the website on Hostgator showing error
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Please reply back.
Thank you in advance
Reply
Answers (
4
)
issue with webapi in mvc
What is right assembly for crystalreportViewer in asp.net?