Friday, October 1, 2010

550 5.7.1 Unable to relay for name@domain.com System.net.mail

one day, the ASMX web service can’t send email any more. When I run a cordbg and attached to the W3wp. turn on to catch all unhandled exception, “ca e”

first, get CDO Exception. then continue, get the error like

550 5.7.1 Unable to relay for name@domain.com

then I change different TO Address, no luck , still the same error.

the Service just a wrapper of  the System.net.mail to send email , and uses a local SMTP server.

it looks like that’s a fat finger issue. When I turn on the Relay setting of the smtp server.

I get the following settings as shown.

image

which means that all relay will be denied. unless you specify it in the exception list.

then just switch it back.

image

Wednesday, September 29, 2010

Test Windows Phone 7 built-in apps in your simulator

By default, when you install the developer tools from developer.windowsphone.com, there is no other Built-in applications except on Internet Explorer application.

If you want to experience the full set like the following simulator.

image

image

All you need is download a customized image from http://forum.xda-developers.com/showthread.php?t=784523

or simply search WM70C1.en-US.bin

then copy the images to C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Emulation\Images

then when you click run in visual studio, you will get the image as shown above.

Windows Phone 7 great features that Iphone /Android doesn’t have

Windows phone features

  • Developer tools + popular programming language.( Silverlight, Visual studio , Team suite. Powerful and free )
    • Blend for designers
    • Visual studio for developers, XNA and Silverlight
    • Team integration, like bug control. Reporting, CMMI-compliance
    • Iphone use the Objective-C, not popular as C# and java
    • Android use java, but no Designer tools , eclipse is just a basic IDE. Blend based , great behavior, animation designer support
    • clip_image001
  • Define one minimum hardware spec for all phones(like With GPS, at least 5M pixels camera. . Instead of just one hardware IPhone(No Keyboard)
  • you define the important things or Life style for you. ( if you think email is important, drag it to the top of home screen. The app icon shows you how many emails you get. Also you can drag gmail, hotmail, yahoomail Icons instead of just one email)
    • Pin a people like you friend or boss to the homescreen
  • Exchange, keep the server policy in sync on phone. ( Security, audit, compliance)
  • Panorama experience, ( most phone just scroll up and down, phone like a full-range length. You can scroll left and right. ), Like People as a contact, scroll right to show the what's new in social network. Email conversations
  • Navigation patterns, Three navigation button(go back, home and search)( go back , Android has the same features+menu button.)
    • Application switching.
    • clip_image002
  • Phone as a camera
    • No need to start the application by clicking several menus.
    • Just click the camera button even in standby mode
    • Both Iphone and android need you start the application explicitly.
    • Slide left and right to preview the pics you taken
  • Xbox Live
    • Gaming experience. Synergy integration like you avatar
    • You achievement
  • Office integration.
    • PPT, excel,
    • Sharepoint.
    • View and doc and update it , then upload it to sharepoint.
  • Features have been in other phones
    • Voice search like iphone and android
      • Click and home windows button to turn on the voice search.
    • Declare what permission you app need
      • Like access internet, call phone. Etc.
      • clip_image003
    • Android
      • clip_image004
  • Trial API
    • One line of code
  • Advertising SDK for windows phone 7
    • Download from ms download center

Thursday, September 23, 2010

How to download and compile, run Tika on windows tutorial

You might get scarred when you first try to download and run Tika on windows, If you dont have some experience of SVN and Maven like me. Here is a quick tutorial to go through these processes.

1. Use subversion client to download the source code of tika.

there is one Windows Shell Extension for Subversion, just download and install it to your windows box. then Right click one folder like C:\temp\tike, and CLick the Svn checkout context menu.

image

enter the SVN source url. http://svn.apache.org/repos/asf/tika/trunk

image

it may take couple seconds to download the source code . Click Ok when done.

image

2. Download Maven , the Build utility like the msbuild, ant. and put the mvn.bat folder to windows PATH.

After the path is set, you should be able to run “mvn” at the command prompt.

image

3. Go the the download tike source folder c:\temp\tika. and run “mvm install”

the builder will download necessary component and compile the project. this make take a while

image

4. run the tika app now.

go to that folder, run “java –jar tika-app-0.8-snapshot.jar –m a.txt”

to pull the metadata of a.txt

image

or –t  yourpdf.pdf to extract the pdf file content

Wednesday, September 22, 2010

tomcat 7 with solr 1.4, HTTP Status 404 - /solr/admin/file/index.jsp

there might be something wrong between the solr 1.4 and tomcat 7. here is one quick story.

After I install the solr 1.4 in tomcat 7. I Open the  /sor/admin and click schema or config .

image

get 404 error.

image

the answer here is pretty simple after I did a lot debugging. Just remove the last slash.

new url will be http://localhost:8888/solr/admin/file?file=schema.xml
   instead of http://localhost:8888/solr/admin/file/?file=schema.xml

after this, you can change the index.jsp locatd in webapps/solr/admin/index.jsp

<td>
  <% if (null != core.getSchemaResource()) { %>
  [<a href="file?file=<%=core.getSchemaResource()%>">Schema</a>]
  <% }
     if (null != core.getConfigResource()) { %>
  [<a href="file?file=<%=core.getConfigResource()%>">Config</a>]
  <% } %>

Solr CSharp /.NET Client Solrsharp , exception Object reference not set to an instance of an object.

After we installed the Solr 1.4 , we use use the solrj as the library Client integration with Solr by using SolrJ .

the latest version of solr is 1.4.x, however, if you want to use the C# client SolrSharp which has not been update sine late 2007. you might need to change something to make the client works with the new version of Solr. say 1.4.

the first exception is called Object reference not set to an instance of an object.

here is one basic snippet to upload one document to solr server via solrsharp. in this example, My solr server is listening on 9999 port. and I started the tcptrace which listens on 8888 and forward all traffic to localhost 9999. based on this, we can see the raw traffic between client and solr server.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using org.apache.solr.SolrSharp.Configuration;
using org.apache.solr.SolrSharp.Update;
using org.apache.solr.SolrSharp.Indexing;

namespace ConsoleApplication6
{
    class TestSolrSharp
    {
        public static void Main()
        {
            //upload document
            try
            {
                SolrSearcher solrSearcher = new SolrSearcher("http://localhost:8888/solr", Mode.ReadWrite);
                SolrUpdater update = new SolrUpdater(solrSearcher);

                UpdateIndexDocument doc = new UpdateIndexDocument();
                doc.Add("id", "1");
                doc.Add("title", "test solr");

                update.PostToIndex(doc, true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

When I run it , I get the following error.

System.NullReferenceException: Object reference not set to an instance of an object.
   at org.apache.solr.SolrSharp.Configuration.Schema.SolrSchema..ctor(SolrSearcher solrSearcher) in C:\Users\xx\Downloads\solrsharp-Dec-30-2007\src\Configuration\Schema\SolrSchema.cs:line 76
   at org.apache.solr.SolrSharp.Configuration.SolrSearcher.SetSolrSchema() in C:\Users\xx\Downloads\solrshar
p-Dec-30-2007\src\Configuration\SolrSearcher.cs:line 93
   at org.apache.solr.SolrSharp.Configuration.SolrSearcher..ctor(String solrUrl, Mode searcherMode) in C:\Users\xx\Downloads\solrsharp-Dec-30-2007\src\Configuration\SolrSearcher.cs:line 77
   at ConsoleApplication6.TestSolrSharp.Main() in C:\Users\xx\documents\visual studio 2010\Projects\ConsoleA
pplication6\ConsoleApplication6\Class1.cs:line 18
Press any key to continue . . .


then I check the tcptrace traffic, get the access exception.

image

it looks like the client library will first pull the Scheme.xml of solr. When it try to get the schema.xml from /solr/admin/get-file.jsp?file=schema.xml, the solr server returns error of No Access.

So we need to make sure http://localhost:9999/solr/admin/get-file.jsp?file=schema.xml is accessible. Why we dont’t have access at this time.

Let’s check the soure code of the get-file.jsp, as shown in the bellow.

<%@ page contentType="text/plain; charset=utf-8" pageEncoding="UTF-8" %>
<%--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%>
<%@ page import="org.apache.solr.core.Config,
                 org.apache.solr.core.SolrCore,
                 org.apache.solr.core.SolrConfig,
                 java.io.InputStream,
                 java.io.InputStreamReader,
                 java.io.Reader,
                 java.util.StringTokenizer,
                 java.util.logging.Logger"%>
<%!
  static Logger log = Logger.getLogger(SolrCore.class.getName());
%>
<%
  // NOTE -- this file will be removed in a future release
  log.warning("Using deprecated JSP: " + request.getRequestURL().append("?").append(request.getQueryString()) + " -- check the ShowFileRequestHandler"  );

  Object ocore = request.getAttribute("org.apache.solr.SolrCore");
  SolrCore core = ocore instanceof SolrCore? (SolrCore) ocore : SolrCore.getSolrCore();
  String fname = request.getParameter("file");
  String optional = request.getParameter("optional");
  String gettableFiles = core.getSolrConfig().get("admin/gettableFiles","");
  StringTokenizer st = new StringTokenizer(gettableFiles);
  InputStream is;
  boolean isValid = false;
  boolean isOptional = false;
  if (fname != null) {
    // Validate fname
    while(st.hasMoreTokens()) {
      if (st.nextToken().compareTo(fname) == 0) isValid = true;
    }
  }
  if (optional!=null && optional.equalsIgnoreCase("y")) {
    isOptional=true;
  }
  if (isValid) {
    try {
    is= core.getSolrConfig().openResource(fname);
    Reader input = new InputStreamReader(is);
    char[] buf = new char[4096];
    while (true) {
      int len = input.read(buf);
      if (len<=0) break;
      out.write(buf,0,len);
    }
    }
    catch (RuntimeException re) {
      if (!isOptional) {
        throw re;
      }
    }
  } else {
    out.println("<ERROR>");
    out.println("Permission denied for file "+ fname);
    out.println("</ERROR>");
  }
%>

from the code, it will check the configuration of gettablefiles in solrconfig.config  by default, there is no such configration in the solrconfig.xml (which comes with the new verson), so it means those files are not getable by default. Why?

the newer version expose this file get functionality via another url called /admin/file?
  which is configed in solrconfigxml

 image

we get the answer , so fix is easy. just put one more entry in the admin section of solrconfig.xml, rememer to restart solr also.

image

Now we can use the solrsharp to upload some documents to solr.

image

For more information.

Monday, September 20, 2010

Important ASP.NET Security Vulnerability for ALL versions. and all app like sharepoint, dnn, reporting service. all aspx pages

MSFT just released one one Microsoft Security Advisory about a security vulnerability in ASP.NET.  This vulnerability exists in all versions of ASP.NET.

what’s can be used by attacker.

  • request and download files within an ASP.NET Application like the web.config file (which often contains sensitive data).
  • even you DLL assembly in Bin directory. ( then they can use .net reflector to see all the source code. )

How to fix it.

  • When error happened ( Exception get thrown 500 or File not exists, status 404 ), DO not return Dedicated Error code. (like 404 or 500, )
    • FOR web.config, enable customers, mode to on or remoteonly. Remove the sub-error code mapping
      • <system.web>
           <customErrors defaultRedirect="GenericError.htm"
                         mode="RemoteOnly">
             <error statusCode="404"
                     redirect="404.htm"/>
              <error statusCode="403"
                     redirect="403.htm"/>

           </customErrors>
        </system.web>

      FOR Customized Handler or Http Module, Make sure status code is always 200 even there are some exception happened
        if(userNoAccess==true)
        {
        response.StatusCode = 403;
        }
         
        try
        {
        }
        catch(Exception ex)
        {
        Log.logError(ex);
        response.StatusCode = 500;
        }

        Change it to
        if(userNoAccess==true)
        {
        response.StatusCode = 200;
        }
         
        try
        {
        }
        catch(Exception ex)
        {
        Log.logError(ex);
        response.StatusCode = 200;
        }

When will MSFT release the patch.
  

  • it looks like the team is still on the investigation phase to get more details, I don't think it will take a long time.
 
Locations of visitors to this page